package com.user.notiy;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.LinkTemplate;
import com.plat.common.UmsConfig;
//app推送通知处理类
public class AppPush {
	
    private String appId = UmsConfig.getProperty("appNotify", "appId");
    private String appKey = UmsConfig.getProperty("appNotify", "appKey");
    private String masterSecret = UmsConfig.getProperty("appNotify", "masterSecret");
    private String url = UmsConfig.getProperty("appNotify", "url");

    public AppPush(String appId,String appKey,String masterSecret){
    	this.appId=appId;
    	this.appKey=appKey;
    	this.masterSecret=masterSecret;
    }
    
    public void appNotify(String  Title,String data){
    	try {
    		IGtPush push = new IGtPush(url, appKey, masterSecret);
    		LinkTemplate template = new LinkTemplate();
    	    template.setAppId(appId);
    	    template.setAppkey(appKey);
    	    template.setTitle(Title);
    	    template.setText(data);
    	    template.setUrl("http://getui.com");
    	    List<String> appIds = new ArrayList<String>();
            appIds.add(appId);
            AppMessage message = new AppMessage();
            message.setData(template);
            message.setAppIdList(appIds);
            message.setOffline(true);
            message.setOfflineExpireTime(1000 * 600);

            IPushResult ret = push.pushMessageToApp(message);
            System.out.println(ret.getResponse().toString());
		} catch (Exception e) {
			// TODO: handle exception
		}
    }
}
